

.LC0:
	.string "arr=%s\n"


.globl main

main:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp

	movl $12345,-0x1000(%rbp) /* i */
	movl $0,-0xff0(%rbp) /* arr */

	leaq -0xff0(%rbp),%rsi /* arr */
	movl -0x1000(%rbp),%edi /* i */
	call itoa 

	leaq -0xff0(%rbp),%rsi /* arr */
	leaq .LC0(%rip),%rdi
	movl $0,%eax 
	call printf 

	movl $0,%eax
	leave
	ret

itoa:
	pushq %rbp
	movq %rsp,%rbp
	subq $0x1000,%rsp
	
	movl %edi,-0x1000(%rbp) /* x */
	movq %rsi,-0xff8(%rbp) /* s */

	movl $0,-0xff0(%rbp) /* v */
	movl $0,-0xfec(%rbp) /* xx */
	movl $0,-0xfe8(%rbp) /* i */
	movl $0,-0xfe4(%rbp) /* j */
	movl $0,-0xfe0(%rbp) /* n */

	movb $0,-0xfd8(%rbp) /* c */

	movl -0x1000(%rbp),%edi /* x */
	call abs
	movl %eax,-0xfec(%rbp) /* xx */

	jmp .Litoa_400

.Litoa_500:
	movl -0xfec(%rbp),%eax /* xx */
	movl $10,%ebx
	xorq %rdx,%rdx
	idivl %ebx
	movl %edx,-0xff0(%rbp) /* v */

	movl -0xff0(%rbp),%eax /* v */
	addl $('0'),%eax
	movl %eax,%ecx

	movl -0xfe0(%rbp),%eax /* n */
	movslq %eax,%rax 
	movq -0xff8(%rbp),%rdi /* s */
	movl %ecx,0(%rdi,%rax,1) /* s[n] */

	addl $1,-0xfe0(%rbp) /* n */

	movl -0xfec(%rbp),%eax /* xx */
	subl -0xff0(%rbp),%eax /* v */
	movl $10,%ebx
	xorq %rdx,%rdx
	idivl %ebx
	movl %eax,-0xfec(%rbp) /* xx */
	
	cmpl $0,-0xfec(%rbp) /* xx */
	jne .Litoa_400
	 
	jmp .Litoa_380 /* break */

.Litoa_400:
	jmp .Litoa_500

.Litoa_380:
	cmpl $0,-0x1000(%rbp) /* x */
	jge .Litoa_350


	movl -0xfe0(%rbp),%eax /* n */
	movslq %eax,%rax 
	movq -0xff8(%rbp),%rdi /* s */
	movb $('-'),0(%rdi,%rax,1) /* s[n] */
	
	addl $1,-0xfe0(%rbp) /* n */

.Litoa_350:
	movl $0,-0xfe8(%rbp) /* i */
	jmp .Litoa_300

.Litoa_340:
	movl -0xfe8(%rbp),%eax /* i */
	movslq %eax,%rax 
	movq -0xff8(%rbp),%rdi /* s */
	movb 0(%rdi,%rax,1),%al /* s[i] */
	movb %al,-0xfd8(%rbp) /* c */

	movl -0xfe0(%rbp),%eax /* n */
	subl $1,%eax
	subl -0xfe8(%rbp),%eax /* i */
	movslq %eax,%rax 
	movq -0xff8(%rbp),%rdi /* s */
	movb 0(%rdi,%rax,1),%cl /* s[n-i-1] */

	movl -0xfe8(%rbp),%eax /* i */
	movslq %eax,%rax 
	movq -0xff8(%rbp),%rdi /* s */
	movb %cl,0(%rdi,%rax,1) /* s[i] */

	movb -0xfd8(%rbp),%cl /* c */

	movl -0xfe0(%rbp),%eax /* n */
	subl $1,%eax
	subl -0xfe8(%rbp),%eax /* i */
	movslq %eax,%rax
	movq -0xff8(%rbp),%rdi /* s */
	movb %cl,0(%rdi,%rax,1) /* s[n-i-1] */

	addl $1,-0xfe8(%rbp) /* i */

.Litoa_300:
	movl -0xfe0(%rbp),%eax /* n */
	sarl $1,%eax
	cmpl -0xfe8(%rbp),%eax /* i */
	jg .Litoa_340


	movl -0xfe0(%rbp),%eax /* n */
	movslq %eax,%rax
	movq -0xff8(%rbp),%rdi /* s */
	movb $0,0(%rdi,%rax,1) /* s[n] */

	movl $0,%eax
	leave
	ret
